package com.zw.pm.module.integrate.daily;


import com.zw.pm.gen.entity.Factory;
import com.zw.pm.module.board.dailyoutput.DailyOutputModel;
import com.zw.pm.module.config.factory.FactoryDao;
import com.zw.pm.module.project.build.ProjectDao;
import com.zw.pm.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 生产日报 服务层
 *
 * @Author: China.sgl
 * @Date: 2019/9/16 09:11
 */
@Service
public class ProduceDailyService {

    @Autowired
    private ProjectDao projectDao;
    @Autowired
    private FactoryDao factoryDao;

    /**
     * 查询生产厂
     *
     * @return list
     */
    public List<Factory> findFactories() {
        return factoryDao.findFactoryAll(new Factory());
    }

    /**
     * 根据条件查询生产日报
     *
     * @param produceDailyModel 查询条件
     * @return 项目列表数据
     */
    public List<ProduceDailyModel> findProject(ProduceDailyModel produceDailyModel){
        return projectDao.findProjectDaily2(produceDailyModel);
    }

    public int findProjectCount(ProduceDailyModel produceDailyModel) {
        return projectDao.findProjectDailyCount(produceDailyModel);
    }

    /**
     * 生产量统计
     *
     * @param dailyOutputModel 条件
     * @return list
     */
    public List<DailyOutputModel> findTotalCountGroupByFactory(DailyOutputModel dailyOutputModel) {

        if (dailyOutputModel.getStartTime() == null) {
            dailyOutputModel.setStartTime(DateUtils.initDate());
        }
        if (dailyOutputModel.getEndTime() == null) {
            dailyOutputModel.setEndTime(DateUtils.initDate());
        }
        return projectDao.findTotalCountGroupByFactory(dailyOutputModel);
    }
}
